package com.tuanzi.loan.business.repository.product.prefilter.impl;

import static com.tuanzi.loan.generated.jooq.loan.tables.LoanProductPrefilter.LOAN_PRODUCT_PREFILTER;

import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.tuanzi.loan.business.repository.product.prefilter.custom.LoanProductPrefilterRepositoryCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepository;
import com.tuanzi.loan.vo.request.product.prefilter.LoanProductPrefilterSearchRequest;
import com.tuanzi.loan.vo.response.product.prefilter.LoanProductPrefilterSearchResponse;

/**
 * @author Ray 2017/09/21
 */
@SuppressWarnings({ "rawtypes" })
public class LoanProductPrefilterRepositoryImpl extends JOOQBaseRepository implements LoanProductPrefilterRepositoryCustom {

	@Override
	protected TableImpl getTable() {
		return LOAN_PRODUCT_PREFILTER;
	}

	@Override
	public Page<LoanProductPrefilterSearchResponse> list(LoanProductPrefilterSearchRequest searchRequest, Pageable pageable) {
		contains(LOAN_PRODUCT_PREFILTER.NAME, searchRequest.getName());
		return search(pageable, x -> {
			LoanProductPrefilterSearchResponse response = new LoanProductPrefilterSearchResponse();
			response.setId(x.get(LOAN_PRODUCT_PREFILTER.ID));
			response.setName(x.get(LOAN_PRODUCT_PREFILTER.NAME));
			response.setCreator(x.get(LOAN_PRODUCT_PREFILTER.CREATOR));
			response.setCreateTime(x.get(LOAN_PRODUCT_PREFILTER.CREATE_TIME));
			response.setUpdator(x.get(LOAN_PRODUCT_PREFILTER.UPDATOR));
			response.setUpdateTime(x.get(LOAN_PRODUCT_PREFILTER.UPDATE_TIME));
			return response;
		});
	}
}
